package com.cbn.ibcp.jishiting.rms.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cbn.ibcp.common.annotation.DataSource;
import com.cbn.ibcp.common.enums.DataSourceType;
import com.cbn.ibcp.jishiting.rms.domain.ResBasePlayConfig;
import com.cbn.ibcp.jishiting.rms.mapper.ResBasePlayConfigMapper;
import com.cbn.ibcp.jishiting.rms.service.IResBasePlayConfigService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
public class ResBasePlayConfigServiceImpl implements IResBasePlayConfigService {

    private final ResBasePlayConfigMapper resBasePlayConfigMapper;


    @DataSource(DataSourceType.ibcp_rms)
    @Override
    public List<ResBasePlayConfig> getListByCpCode(String cpCode) {
        if (StrUtil.isBlank(cpCode)) {
            return null;
        }
        LambdaQueryWrapper<ResBasePlayConfig> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ResBasePlayConfig::getStatus, 1);
        queryWrapper.eq(ResBasePlayConfig::getConfigKey, "playSource");
        queryWrapper.apply("find_in_set ('" + cpCode + "', config_val)");
        return resBasePlayConfigMapper.selectList(queryWrapper);
    }
}
